package com.wolffy.flink.combine;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class UnionDemo {
    public static void main(String[] args) throws Exception {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<Integer> source1 = env.fromElements(1, 2, 3);
        DataStreamSource<Integer> source2 = env.fromElements(11, 22, 33);
        DataStreamSource<String> source3 = env.fromElements("111", "222", "333");

        // 流的数据类型必须一致 一次可以合并多条流
        DataStream<Integer> union1 = source1.union(source2).union(source3.map(r -> Integer.valueOf(r)));
        DataStream<Integer> union2 = source1.union(source2, source3.map(r -> Integer.valueOf(r)));
        union1.print();
        union2.print();

        env.execute();
    }
}
